#ifndef _YOLOV8_DETECT_H_
#define _YOLOV8_DETECT_H_

#include <opencv2/opencv.hpp>
#include <onnxruntime_cxx_api.h>
#include "model_base.h"

const std::vector<float> IMAGE_MEAN{123.675f, 116.28f, 123.675f};
const std::vector<float> IMAGE_STD{57.375f, 57.12f, 58.395f};

struct DetectBox
{
    int left;
    int top;
    int right;
    int bottom;
    float score;
    int label;
    std::string label_name;

    //  结构体初始化
    DetectBox()
    {
        left = -1;
        top = -1;
        right = -1;
        bottom = -1;
        score = -1.0;
        label = -1;
        label_name = "";
    }

    bool IsValid() const
    {
        return left != -1 && top != -1 && right != -1 && bottom != -1 && score != -1.0 && label != -1 && label_name != "";
    }
};

static bool BoxCompare(const DetectBox &a, const DetectBox &b)
{
    return a.score > b.score;
}

class Yolov8Detect : public ModelBase
{
public:
    Yolov8Detect();
    ~Yolov8Detect();

public:
    std::vector<DetectBox> Inference(const cv::Mat input_mat, float scale,
                                     std::vector<int> &padding,
                                     float score_threshold = 0.5,
                                     float iou_threshold = 0.5,
                                     float nms_threshold = 0.5);

    // float LetterBox(const cv::Mat &input_mat, cv::Mat &output_mat, // 修改这里
    //                 const cv::Size &new_shape,
    //                 const cv::Scalar &color,
    //                 bool scale_up);

private:
    int padW;
    int padH;
    std::vector<std::string> class_names =
        {"fist", "stop", "palm", "rock", "one", "no_gesture"};
};

#endif // _HAND_DETECT_H_